﻿using System;
using GdNet.Integrations.NHibernate.Assistants;
using GdNet.Integrations.NHibernate.Mapping;
using GdNet.WebFramework.Domain.ContentManagement;
using NHibernate.Mapping.ByCode;

namespace GdNet.WebFramework.Mapping.ContentManagement
{
    public class ContentPartMapping : AbstractJoinedSubclassMapping<ContentPart, Guid>, IEntityMapping
    {
        public ContentPartMapping()
        {
            base.Property(e => e.Name);
            base.Property(e => e.Details);
            base.Property(e => e.Position);

            base.ManyToOne(x => x.ContentItem, m =>
            {
                m.Lazy(LazyRelation.Proxy);
                m.Access(Accessor.Property);
                m.Column(MappingAssistant.GetForeignKeyColumn<ContentPart, ContentItem>(cp => cp.ContentItem));
            });
        }
    }
}
